<html>
<head><meta charset="utf-8"><title>ptr -&gt; Option&lt;&amp;&gt; conversion? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/ptr.20-.3E.20Option.3C.26.3E.20conversion.3F.html">ptr -&gt; Option&lt;&amp;&gt; conversion?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210917110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/ptr%20-%3E%20Option%3C%26%3E%20conversion%3F/near/210917110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/ptr.20-.3E.20Option.3C.26.3E.20conversion.3F.html#210917110">(Sep 22 2020 at 19:08)</a>:</h4>
<p>Whenever I have a raw pointer that I know is either a valid reference or null, converting it to <code>Option&lt;&amp; T&gt;</code> always feels a bit verbose. Maybe there should be a function in <code>core::ptr</code>?</p>



<a name="210917231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/ptr%20-%3E%20Option%3C%26%3E%20conversion%3F/near/210917231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/ptr.20-.3E.20Option.3C.26.3E.20conversion.3F.html#210917231">(Sep 22 2020 at 19:09)</a>:</h4>
<p>do you mean <a href="https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref">https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref</a> ?</p>



<a name="210936870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/ptr%20-%3E%20Option%3C%26%3E%20conversion%3F/near/210936870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/ptr.20-.3E.20Option.3C.26.3E.20conversion.3F.html#210936870">(Sep 22 2020 at 22:01)</a>:</h4>
<p>I see now that the docs here don't say that you can't call this function if there's already a unique reference anywhere, and this can also invalidate other mut pointers I think?</p>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span></p>



<a name="210940947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/ptr%20-%3E%20Option%3C%26%3E%20conversion%3F/near/210940947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/ptr.20-.3E.20Option.3C.26.3E.20conversion.3F.html#210940947">(Sep 22 2020 at 22:51)</a>:</h4>
<p>they'd still be allowed to be turned to other &amp;T</p>



<a name="210948937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/ptr%20-%3E%20Option%3C%26%3E%20conversion%3F/near/210948937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/ptr.20-.3E.20Option.3C.26.3E.20conversion.3F.html#210948937">(Sep 23 2020 at 00:57)</a>:</h4>
<p><span class="user-mention" data-user-id="249222">@Elichai Turkel</span> hm, perhaps reasonable to add, though that's true of any code obtaining a &amp;T</p>



<a name="210949498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/ptr%20-%3E%20Option%3C%26%3E%20conversion%3F/near/210949498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/ptr.20-.3E.20Option.3C.26.3E.20conversion.3F.html#210949498">(Sep 23 2020 at 01:07)</a>:</h4>
<p>Invalidation shouldn't be documented, that's (AFAIK) not a detail currently acknowledged by reference or anything formal, it's a potential extension as part of stacked borrows</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>